﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PublicClass;
using PublicClass.Shift;
using S.Produce.Read.Api.Application.Commands.ShiftCommands;

namespace S.Produce.Read.Api.Controllers
{
    /// <summary>
    /// 转舍控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShiftSelectsController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ShiftSelectsController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取羊只品种下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetBreed()
        {
            var res = new List<object>();
            foreach (var item in Enum.GetValues<Breed>())
            {
                res.Add(new
                {
                    name = item.ToString(),
                    value = item,
                });
            }
            return Ok(res);
        }

        /// <summary>
        /// 获取羊只转舍类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTransferType()
        {
            var res = new List<object>();
            foreach (var item in Enum.GetValues<TransferType>())
            {
                res.Add(new
                {
                    name = item.ToString(),
                    value = item
                });
            }
            return Ok(res);
        }


        /// <summary>
        /// 获取转舍信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetShiftList([FromQuery] ShiftSelectCommand command)
        {
            return Ok(await _mediator.Send(command));
        }

        /// <summary>
        /// 回填转舍信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetShiftInfo([FromQuery] ShiftBackfillCommand command)
        {
            return Ok(await _mediator.Send(command));
        }

        /// <summary>
        /// 根据耳号获取羊只转舍信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetEarShiftInfo([FromQuery] ShiftEarCommand command)
        {
            return Ok(await _mediator.Send(command));
        }
    }
}
